package com.ruoyi.flowable.multiInstance;

import com.ruoyi.common.core.domain.entity.SysUser;
import com.ruoyi.system.service.ISysPostService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.List;

@Slf4j
@Component
public class MulInstService {

    @Resource
    private ISysPostService postService;

    //会签 固定返回 使用 ${mulInstService.getTestUsers()}
    public List<String> getTestUsers(){
        List<String> list = new ArrayList<>();
        list.add("admin");
        list.add("test");
        list.add("lionli");
        return list;
    }

    //会签 解析表单字段 使用 ${mulInstService.getUsers(cascader49078)}
    public List<String> getUsers(List<List<String>> users){
        log.info(users.toString());
        List<String> list = new ArrayList<>();
        for (List<String> user : users) {
            if (user.size()>1){
                list.add(user.get(1));
            }
        }
        log.info(list.toString());
        return list;
    }

    // 会签 解析岗位id ${mulInstService.getPostUsers(123456)}
    public List<String> getPostUsers(Long postId){
        List<String> list = new ArrayList<>();
        List<SysUser> sysUsers = postService.selectUserNamesByPostId(postId);
        for (SysUser sysUser : sysUsers) {
            list.add(sysUser.getUserName());
        }
        log.info(list.toString());
        return list;
    }

}
